/* 
** test array 
*/
#include <stdio.h>
#include <string.h>

static char * lcs_logname = "lcs_statement";
static char lcs_logbuf[512];
static void lcs_testlog()
{
	int fp;
	
	fp = fopen( lcs_logname, "a" );
	if( !fp ) return;

	printf( "%s", lcs_logbuf );
	fprintf( fp, "%s", lcs_logbuf );
	
	fclose( fp );
}

/*
** test begin...
*/

int lcs_stmt_if( int n )
{
	if( n == 1 ){
		sprintf( lcs_logbuf, "%s ", "1" );	
		lcs_testlog();
	}
	if( n == 2 && n == 1 ){
		sprintf( lcs_logbuf, "%s ", "2" );	
		lcs_testlog();
	}
	if( n == 3 || n == 2 ){
		sprintf( lcs_logbuf, "%s ", "3" );	
		lcs_testlog();
	}

	if( n == 613 ){
		sprintf( lcs_logbuf, "%s ", "613" );	
		lcs_testlog();
	}
	else if( n == 614 ){
		sprintf( lcs_logbuf, "%s ", "614" );	
		lcs_testlog();
	}
	else if( n == 615 ){
		sprintf( lcs_logbuf, "%s ", "615" );	
		lcs_testlog();
	}
	else{
		sprintf( lcs_logbuf, "=%d ", n );	
		lcs_testlog();
	}
	return 0;
}

int lcs_stmt_while( int n )
{
	int save = n;
	int loop = 2;
	while( loop-- ){
		sprintf( lcs_logbuf, "-%d ", loop );	
		lcs_testlog();

		n = save;
		while( n-- ){
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
		}

		n = save;
		while( n-- ){
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
			break;
		}

		n = save;
		while( n-- ){
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
			continue;
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
		}
	}
	return 0;
}

int lcs_stmt_dowhile( int n )
{
	int save = n;
	int loop = 2;
	do{
		n = save;
		do{
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
		}while( --n );

		n = save;
		do{
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
			break;
		}while( --n );

		n = save;
		do{
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
			continue;
			sprintf( lcs_logbuf, "%d ", n );	
			lcs_testlog();
		}while( --n );

		sprintf( lcs_logbuf, "-%d ", loop );	
		lcs_testlog();
	}while( --loop );
	return 0;
}

int lcs_stmt_for( int n )
{
	int i;
	for( i=0; i<n; i++ ){
		sprintf( lcs_logbuf, "%d ", i );	
		lcs_testlog();
	}

	i=0;
	for(;;){
		sprintf( lcs_logbuf, "%d ", i );	
		lcs_testlog();
		i++;
		if( i>n ) break;
	}
	i=0;
	for(0;0;0){
		sprintf( lcs_logbuf, "%d ", i );	
		lcs_testlog();
		i++;
		if( i>n ) break;
	}
	i=0;
	for(0;1;0){
		sprintf( lcs_logbuf, "%d ", i );	
		lcs_testlog();
		i++;
		if( i>n ) break;
	}
	return 0;
}

int lcs_stmt_switch( int n )
{
	switch( n ){
	case 1:
		sprintf( lcs_logbuf, "%s ", "1" );	
		lcs_testlog();
		break;
	case 2:
		sprintf( lcs_logbuf, "%s ", "2" );	
		lcs_testlog();
		break;
	case 3:
		sprintf( lcs_logbuf, "%s ", "3" );	
		lcs_testlog();
		break;
	default:
		sprintf( lcs_logbuf, "=%d ", n );	
		lcs_testlog();
		break;
	case 613:
		sprintf( lcs_logbuf, "%s ", "613" );	
		lcs_testlog();
	case 614:
		sprintf( lcs_logbuf, "%s ", "614" );	
		lcs_testlog();
	case 615:
		sprintf( lcs_logbuf, "%s ", "615" );	
		lcs_testlog();
	}
	return 0;
}

int lcs_stmt_block()
{
	int a = 1;
	{	
		int b = 2;
		{	
			int c = 3;
			sprintf( lcs_logbuf, "%d ", c );
			lcs_testlog();
			{
				int d = 4;
				sprintf( lcs_logbuf, "%d ", d );
				lcs_testlog();
			}
		}
		sprintf( lcs_logbuf, "%d ", b );
		lcs_testlog();
	}
	sprintf( lcs_logbuf, "%d ", a );
	lcs_testlog();
	
	do{	
		int b = 5;
		sprintf( lcs_logbuf, "%d ", b );
		lcs_testlog();
		{	
			int c = 6;
			do{
				int d = 7;
				sprintf( lcs_logbuf, "%d ", d );
				lcs_testlog();
			}while(0);
			sprintf( lcs_logbuf, "%d ", c );
			lcs_testlog();
		}
	}while(0);

	return 0;
}

int lcs_statement()
{
	int i;
	int sn[32] = {1,2,3,4,5,6,7,613,614,615,616};
	
	/*test if*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_if: " );
	lcs_testlog();
	for( i=0; i<11; i++ ){
		lcs_stmt_if( sn[i] );
	}
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();
	
	/*test while*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_while: " );
	lcs_testlog();
	lcs_stmt_while( 5 );
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();

	/*test dowhile*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_dowhile: " );
	lcs_testlog();
	lcs_stmt_dowhile( 5 );
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();

	/*test for*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_for: " );
	lcs_testlog();
	lcs_stmt_for( 5 );
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();

	/*test switch*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_switch: " );
	lcs_testlog();
	for( i=0; i<11; i++ ){
		lcs_stmt_switch( sn[i] );
	}
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();

	/*test switch*/
	sprintf( lcs_logbuf, "%-20s", "test stmt_block: " );
	lcs_testlog();
	lcs_stmt_block();
	sprintf( lcs_logbuf, "\n" );
	lcs_testlog();

	return 0;
}
